<div class="row-fluid">
    <?php echo $this->render('/listados/menu.phtml'); ?>

    <div class="well well-small">
        <legend>Promesas de Juicios </legend>
        <form name="form_busqueda" class="noPrint" method="POST">
            <div class="row-fluid">
                <div class="control-group" style="margin-bottom:0px;display:inline-block;">
                    <label class="control-label">Desde</label>
                    <input id="desde" name="desde" value="<?php echo $this->desde ? $this->desde : "" ?>" style="width:75px;" type="text" />
                </div>
                <div class="control-group" style="margin-bottom:0px;display:inline-block;">
                    <label class="control-label">Hasta</label>
                    <input id="hasta" name="hasta"   value="<?php echo $this->hasta ? $this->hasta : "" ?>" style="width:75px;" type="text" />
                </div>
                <div class="control-group" style="margin-bottom:0px;display:inline-block;">
                    <label>Usuario a Cargo</label>
                    <select id="usuario_asignado" name="usuario_asignado" class="input-medium">
                        <option value="todos">Todos</option>
                        <?php foreach ($this->usuarios as $usuario) { ?>
                            <?php if (!$usuario->getPerfil()->esAdministrador()) continue; ?>
                            <option value="<?php echo $usuario->getId(); ?>" <?php echo $this->usuarioAsignado == $usuario->getId() ? "selected" : ""; ?> >
                                <?php echo $usuario->getMail(); ?></option>
                        <?php } ?>
                    </select>
                </div>
                <div class="control-group" style="margin-bottom:0px;display:inline-block;">
                    <label class="checkbox">
                        <input type="checkbox" name="pendiente_de_cobro" value="1"  <?php echo $this->pendienteDeCobro == 1 ? "checked" : "" ?> > Pendiente de Cobro
                    </label>
                </div>
                <div class="control-group" style="display:inline-block;">
                    <input style="margin-bottom:8px;" class="btn" value="Buscar" type="submit" />
                </div>
            </div>
        </form>
        
        <div class="row-fluid">
            <span>
                <?php
                $subtitulo = '<b>' . count($this->juicios) . '</b> juicios encontrados entre <b>' . $this->desde . '</b> a <b>' . $this->hasta . '</b>';
                echo $subtitulo;
                ?>
            </span>
            <button type="button" onclick="PrintElement('#tabla_por_estados')" class="btn btn-inverse noPrint" style="float:right; margin:3px;"><i class=" icon-print icon-white"></i>  Imprimir</button>&nbsp;&nbsp;
        </div>
        
        <div class="row-fluid ">
            <table id="tabla_promesas" class="tabla_reducida">
                <thead>
                    <tr>
                        <th>Juicio</th><th>Apellido y Nombres</th> <th>Observaci&oacute;n</th><th>Fecha</th><th>Fecha Promesa</th><th>Pend. Cobro</th>
                    </tr>
                </thead>
                <tbody>
                    <?php foreach ($this->promesas as $promesa) { ?>
                        <tr>
                            <td>
                                <a href="<?php echo $this->baseUrl() . "/juicios/juicio/registrar/juicio_id/" . $promesa->getJuicio()->getId(); ?>">
                                <?php echo $promesa->getJuicio()->getId(); ?></a>
                            </td>
                            <td><?php echo $promesa->getJuicio()->getCliente()->getApellido() . ", " . $promesa->getJuicio()->getCliente()->getNombres(); ?></td>
                            <td><?php echo $promesa->getComentario(); ?></td>
                            <td><?php echo $promesa->getFecha()->format('d/m/Y'); ?></td>
                            <td><?php echo $promesa->getFechaPromesa()->format('d/m/Y'); ?></td>
                            <td><?php echo $promesa->getPendienteDeCobro() ? "SI" : ""; ?></td>
                        </tr>
                    <?php } ?>
                </tbody>
            </table>
        </div>
    </div>
</div>


<script type="text/javascript">
    $(function() {
        $("#desde").datepicker({dateFormat: 'dd/mm/yy', changeMonth: true, changeYear: true});
        $("#hasta").datepicker({dateFormat: 'dd/mm/yy', changeMonth: true, changeYear: true});

        $("#tabla_promesas").chromatable({
            width: "100%",
            height: "450px",
            scrolling: "yes"
        });

        $("#tabla_por_estados").chromatable({
            width: "100%",
            height: "350px",
            scrolling: "yes"
        });
    });

    //Simple wrapper to pass a jQuery object to your new window
    function PrintElement(elem) {
        Popup($(elem).html());
    }

    //Creates a new window and populates it with your content
    function Popup(data) {
        //Create your new window
        var w = window.open('', 'Creditos <?php echo $this->desde ?> - <?php echo $this->hasta ?>', 'height=600,width=800');
        w.document.write('<html><head><title>Creditos <?php echo $this->desde ?> - <?php echo $this->hasta ?></title>');
        //Include your stylesheet (optional)
        w.document.write('<link rel="stylesheet" href="<?php echo $this->baseUrl("/bootstrap/css/bootstrap.css") ?>" type="text/css" />');
        w.document.write('</head><body>');
        w.document.write('<h2>Creditos <?php echo $this->desde ?> - <?php echo $this->hasta ?></h2>');
        //Write your content
        w.document.write("<table class='table table-bordered'>" + data + "</table>");
        w.document.write('</body></html>');
        w.print();
        w.close();

        return true;
    }
</script>